package com.gaojiawei.multiThread01_ThreadCreateMethod;

/**
 * 线程创建方法2：继承Thread方法重写run方法
 * 写法：使用匿名内部类，lamba表达式
 */
public class l2_ThreadCreateMethod2 {
    public static void main(String[] args) {
        //普通写法
        MythreadRunable mythreadRunable = new MythreadRunable();
        Thread thread = new Thread(mythreadRunable);
        thread.start();

        //使用匿名内部类
        new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i = 0;i<100;i++){
                    System.out.println("Mythreadniming"+i);
                }
            }
        }).start();


        //使用lamba表达式
        new Thread(() -> {
            for(int i = 0;i<100;i++){
                System.out.println("Mainthreadlamba"+i);
            }
        }).start();


        //主线程
        for(int i = 0;i<100;i++){
            System.out.println("Mainthread"+i);
        }
    }

}

class MythreadRunable implements Runnable {

    @Override
    public void run() {
        for(int i = 0;i<100;i++){
            System.out.println("Mythread"+i);
        }
    }
}
